package com.quiz.action.sdk;

import android.app.Activity;
import android.content.Context;
import android.util.Log;

import com.applovin.sdk.AppLovinMediationProvider;
import com.applovin.sdk.AppLovinPrivacySettings;
import com.applovin.sdk.AppLovinSdk;
import com.applovin.sdk.AppLovinSdkConfiguration;
import com.applovin.sdk.AppLovinSdkInitializationConfiguration;
import com.quiz.action.sdk.ad.QActionlMaxReward;
import com.quiz.action.sdk.bridge.QActionCocosBridge;
import com.quiz.action.sdk.utils.QActionToastUtil;
import com.quiz.action.sdk.utils.QActionUtils;

public class QActionSDKManager{

    public static QActionSDKManager getInstance() {
        return InstanceHolder.GAME_APPLICATION;
    }

    private static class InstanceHolder {
        private static final QActionSDKManager GAME_APPLICATION = new QActionSDKManager();
    }

    public void init(Activity activity) {
        Log.e("QAction", "onCreateonCreate");
        Context mApplication = activity.getApplicationContext();
        QActionBusiness.init(mApplication);

        initAd(mApplication);

        QActionCocosBridge.getInstance().setMainGameActivity(activity);

        QActionToastUtil.init(activity);
    }

    private void initAd(Context mApplication) {
        setAppLovinPrivacySettings();

        initMax(mApplication);
    }

    private void initMax(Context mApplication) {
        AppLovinSdkInitializationConfiguration initConfig = AppLovinSdkInitializationConfiguration.builder(
                        QActionUtils.decrypt(QActionConstant.MAX_KEY))
                .setMediationProvider(AppLovinMediationProvider.MAX)
                .build();
        AppLovinSdk.getInstance(mApplication).initialize(initConfig, new AppLovinSdk.SdkInitializationListener() {
            @Override
            public void onSdkInitialized(final AppLovinSdkConfiguration config) {
//                AppLovinSdk.getInstance(context).showMediationDebugger();
                Log.e("QAction", "onSdkInitialized");
                QActionlMaxReward.getInstance().loadRewardAd(mApplication);
            }
        });
    }

    private void setAppLovinPrivacySettings() {
        AppLovinPrivacySettings.setHasUserConsent(true);
        AppLovinPrivacySettings.setDoNotSell(false);
    }

}
